package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysProject;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.vo.SysWorkPlanVo;
import com.ruoyi.system.mapper.SysProjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysWorkPlanMapper;
import com.ruoyi.system.domain.SysWorkPlan;
import com.ruoyi.system.service.ISysWorkPlanService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 工作计划Service业务层处理
 *
 * @author ruoyi
 * @date 2025-08-30
 */
@Service
public class SysWorkPlanServiceImpl implements ISysWorkPlanService
{
    @Autowired
    private SysWorkPlanMapper sysWorkPlanMapper;

    @Autowired
    private SysProjectMapper sysProjectMapper;

    /**
     * 查询工作计划
     *
     * @param planId 工作计划主键
     * @return 工作计划
     */
    @Override
    public SysWorkPlanVo selectSysWorkPlanByPlanId(Long planId)
    {
        return sysWorkPlanMapper.selectSysWorkPlanByPlanId(planId);
    }

    /**
     * 查询工作计划列表
     *
     * @param sysWorkPlan 工作计划
     * @return 工作计划
     */
    @Override
    public List<SysWorkPlan> selectSysWorkPlanList(SysWorkPlan sysWorkPlan)
    {
        return sysWorkPlanMapper.selectSysWorkPlanList(sysWorkPlan);
    }

    /**
     * 新增工作计划
     *
     * @param sysWorkPlan 工作计划
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insertSysWorkPlan(SysWorkPlan sysWorkPlan)
    {
        sysWorkPlan.setCreateTime(DateUtils.getNowDate());

        SysProject sysProject = new SysProject();
        sysProject.setProjectId(sysWorkPlan.getProjectId());
        sysProject.setAccumulateNum(sysWorkPlan.getAccumulateNum());
        sysProjectMapper.updateSysProject(sysProject);

        return sysWorkPlanMapper.insertSysWorkPlan(sysWorkPlan);
    }

    /**
     * 修改工作计划
     *
     * @param sysWorkPlan 工作计划
     * @return 结果
     */

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateSysWorkPlan(SysWorkPlan sysWorkPlan)
    {
        sysWorkPlan.setUpdateTime(DateUtils.getNowDate());

        SysProject sysProject = new SysProject();
        sysProject.setProjectId(sysWorkPlan.getProjectId());
        sysProject.setAccumulateNum(sysWorkPlan.getAccumulateNum());
        sysProjectMapper.updateSysProject(sysProject);

        return sysWorkPlanMapper.updateSysWorkPlan(sysWorkPlan);
    }

    /**
     * 批量删除工作计划
     *
     * @param planIds 需要删除的工作计划主键
     * @return 结果
     */
    @Override
    public int deleteSysWorkPlanByPlanIds(Long[] planIds)
    {
        return sysWorkPlanMapper.deleteSysWorkPlanByPlanIds(planIds);
    }

    /**
     * 删除工作计划信息
     *
     * @param planId 工作计划主键
     * @return 结果
     */
    @Override
    public int deleteSysWorkPlanByPlanId(Long planId)
    {
        return sysWorkPlanMapper.deleteSysWorkPlanByPlanId(planId);
    }
}
